From: John Du Hart Date: Tue, 15 Nov 2011 00:37:38 +0000 (+0000) Subject: Added function to SpecialPage to simplify permissions checking in SpecialPage classes. X-Git-Tag: 1.31.0-rc.0~26502 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=2133770f23aef7cc7c6daada3670adad141950d1;p=lhc%2Fweb%2Fwiklou.git Added function to SpecialPage to simplify permissions checking in SpecialPage classes. --- diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index a95046c5c4..7d51021677 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -510,6 +510,17 @@ class SpecialPage { throw new PermissionsError( $this->mRestriction ); } + /** + * Checks if userCanExecute, and if not throws a PermissionsError + * + * @since 1.19 + */ + public function checkPermissions() { + if ( !$this->userCanExecute( $this->getUser() ) ) { + $this->displayRestrictionError(); + } + } + /** * Sets headers - this should be called from the execute() method of all derived classes! */ @@ -530,18 +541,15 @@ class SpecialPage { */ function execute( $par ) { $this->setHeaders(); + $this->checkPermissions(); - if ( $this->userCanExecute( $this->getUser() ) ) { - $func = $this->mFunction; - // only load file if the function does not exist - if( !is_callable($func) && $this->mFile ) { - require_once( $this->mFile ); - } - $this->outputHeader(); - call_user_func( $func, $par, $this ); - } else { - $this->displayRestrictionError(); + $func = $this->mFunction; + // only load file if the function does not exist + if( !is_callable($func) && $this->mFile ) { + require_once( $this->mFile ); } + $this->outputHeader(); + call_user_func( $func, $par, $this ); } /**